<template>
  <tl-sub-page :visible.sync="visible" :title="title" v-dialogDrag class="tl-dialog" @open="open" @close="close">
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="120px" :disabled="disableEditSubmit">
      <!-- <el-row>
        <el-col :span="24">
          <el-form-item label="所属等级">
            <el-checkbox-group v-model="selectedLevelList">
              <el-checkbox v-for="item in codeModel.sourcelevelList" :key="item.code" :label="item.code.toString()">
                {{ item.name }}
              </el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-col>
      </el-row> -->
      <el-row>
        <el-col :span="12">
          <el-form-item label="名称" prop="name" :rules="rules.validateRequire">
            <el-input v-model="model.name" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="状态" prop="state">
            <el-select v-model="model.state">
              <el-option v-for="item in codeModel.stateList" :key="item.code" :label="item.name" :value="parseInt(item.code)" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="职能部门" prop="deptcode" :rules="rules.validateRequire">
            <tl-ref-tree v-model="model.deptcode" :initDisplayData.sync="model.dispdeptcode" dataType="code" :queryTreeUrl="url.queryDeptTree" :queryDataUrl="url.queryDeptList" :singleSelect="true"></tl-ref-tree>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="负责人" prop="usercode" :rules="rules.validateRequire">
            <tl-ref-user v-model="model.usercode" :initDisplayData.sync="model.dispusercode" dataType="code" :singleSelect="true" @confirm="queryUserInfo"></tl-ref-user>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="联系电话" prop="telephone">
            <el-input v-model="model.telephone" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="邮箱" prop="email">
            <el-input v-model="model.email" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="备注" prop="description">
            <el-input v-model="model.description" type="textarea" :rows="4" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="排序号" prop="sortcode">
            <el-input-number v-model="model.sortcode" :min="0" :max="10000"></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="有效" prop="enabled">
            <el-radio-group v-model="model.enabled">
              <el-radio :label="parseInt(item.code)" :key="item.code" v-for="item in codeModel.enabledList">{{ item.name }}</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="disableEditSubmit === false">确认</el-button>
    </div>
  </tl-sub-page>
</template>

<script>
/** mixins */
import { queryDataCode } from '@tapui/api/dataCode'
import { mixin_edit } from '@tapui/mixins/mixin_edit'
import { putAction, getAction, postAction } from '@tapui/utils/http'
export default {
  mixins: [mixin_edit],
  data() {
    return {
      moduleTitle: '会议室资源',
      url: {
        add: '/toa/boardroomSource/insert',
        edit: '/toa/boardroomSource/update',
        load: '/toa/boardroomSource/load',
        queryCodeList: '/toa/boardroomSource/dataCodeList',
        queryDeptTree: '/cbo/dept/queryTreeList',
        queryDeptList: '/cbo/dept/list',
        queryUserInfo: '/cbo/user/load'
      },
      // 资源等级可选列表
      selectedLevelList: []
    }
  },
  methods: {
    queryUserInfo(userList) {
      if (userList && userList.length > 0) {
        if (userList[0].mobile) this.$set(this.model, 'telephone', userList[0].mobile)
        if (userList[0].email) this.$set(this.model, 'email', userList[0].email)
      }
    },
    beforeSubmit() {
      this.model.sourcelevellist = this.selectedLevelList.join(',')
      return true
    },
    loaded() {
      if (this.model.sourcelevellist) {
        this.selectedLevelList = this.model.sourcelevellist.split(',')
      } else {
        this.selectedLevelList = []
      }
    },
    assignDefaultValue() {
      this.$set(this.model, 'state', parseInt(this.codeModel.stateList[0].code))
    }
  }
}
</script>

<style scoped></style>
